package org.liam.ltrans.stage;

import javafx.concurrent.Task;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.Background;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.util.Objects;

/**
 * @author chenli
 * @version 1.0
 * @date 2023/12/15 17:37
 */
public class ProgressStage {
    private Stage stage;


    public ProgressStage() {
    }



    /**
     * 显示
     */
    public void show() {
        stage.show();
    }

    public void close() {
        stage.close();
    }

    public void initUI(String ad) {
        stage = new Stage();
        stage.initOwner(null);
        // style
        stage.initStyle(StageStyle.UNDECORATED);
        stage.initStyle(StageStyle.TRANSPARENT);
        stage.initModality(Modality.APPLICATION_MODAL);

        // message
        Label adLbl = new Label(ad);
        adLbl.setTextFill(Color.BLUE);

        // progress
        ProgressIndicator indicator = new ProgressIndicator();
        indicator.setProgress(-1);


        // pack
        VBox vBox = new VBox();
        vBox.setSpacing(10);
        vBox.setBackground(Background.EMPTY);
        vBox.getChildren().addAll(indicator, adLbl);

        // scene
        Scene scene = new Scene(vBox);
        scene.setFill(null);
        stage.setScene(scene);
        stage.setWidth(ad.length() * 8 + 10);
        stage.setHeight(100);

//        // show center of parent
//        double x = parent.getX() + (parent.getWidth() - stage.getWidth()) / 2;
//        double y = parent.getY() + (parent.getHeight() - stage.getHeight()) / 2;
//        stage.setX(x);
//        stage.setY(y);

    }
}
